package tack11;

import chapter11.SuperArray;

import java.util.Scanner;

/**
 * 学生管理系统
 */
public class StudentUI  {
    private SuperArray ary = new SuperArray();
    private Scanner sc = new Scanner(System.in);
    public StudentUI(){
        ary.add(new Student("张飞","男",20));
        ary.add(new Student("关羽","男",25));
        ary.add(new Student("刘备","男",30));
        menu();
    }

    /**
     * 菜单界面
     */
    public void menu(){
        System.out.println("欢迎使用学生管理程序");
        while(true){
            System.out.println("请选择：1-查看所有学生 2-增加 3-修改 4-删除 5-退出");
            int input = sc.nextInt();
            if(input == 1){
                show();
            }else if(input == 2){
                add();
            }else if(input == 3){
                update();
            }else if(input == 4){
                remove();
            }else if(input == 5){

            }
        }
    }

    /**
     * 显示所有学生
     */
    public void show(){
        for(int i = 0 ;i < ary.size();i++){
            Student student = (Student)ary.gat(i);
            System.out.println(student.getName() + "," + student.getGender() + "," + student.getAge());
        }
    }

    /*** 增加学生*/
    public void add(){
        System.out.println("请输入该学生的 姓名 性别 年龄");
        String name = sc.next();
        String gender = sc.next();
        int age = sc.nextInt();
        Student student = new Student();
        ary.add(new Student(name,gender,age));
        System.out.println(student.getName()+" "+ student.getGender() + "" + student.getAge() );
    }

    /*** 修改学生*/
    public void update(){
        System.out.println("输入学生的名字");
        String name =sc.next();
        for(int i = 0 ; i < ary.size() ;i ++){
            Student student = (Student)ary.gat(i);
            if(name.equals(student.getName())){
                System.out.println("请输入要修改信息 1 名字 2 性别 3 年龄");
                int a = sc.nextInt();
                if( a == 1){
                    System.out.println("请输入更正后的姓名");
                    String name1 = sc.next();
                    student.setName(name1);
                    System.out.println("更正成功");
                    return;
                }
                if ( a == 2){
                    System.out.println("请输入更正性别");
                    String gender = sc.next();
                    student.setGender(gender);
                    System.out.println("更正成功");
                    return;
                }
                if( a == 3){
                    System.out.println("请输入更正后的年龄");
                    int age = sc.nextInt();
                    student.setAge(age);
                    return;
                }
            }
        }
        System.out.println("查无此人");
    }

    /*** 删除学生*/
    public void remove(){
        System.out.println("请输入要删除同学的名字");
        String name = sc.next();
        for(int i = 0 ; i < ary.size(); i ++){
            Student student = (Student)ary.gat(i);
            if(name.equals(student.getName())){
                ary.remove(i);
                System.out.println("删除成功");
                return;
            }

        }
        System.out.println("没有这位同学");
    }

    public static void main(String[] args) {
        new StudentUI();
    }
}
